package com.client.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class EmailsConfiguration {
    @Bean  // 创建JavaMailSender实例
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        // QQ邮箱SMTP服务器配置
        sender.setHost("smtp.qq.com");  // SMTP服务器地址
        sender.setPort(587);            // TLS端口
        sender.setUsername("2836126390@qq.com"); // 发件邮箱
        sender.setPassword("vqcfkggthibkdejg");     // 注意是授权码不是密码！

        Properties props = sender.getJavaMailProperties();
        props.put("mail.smtp.auth", "true");          // 启用认证
        props.put("mail.smtp.starttls.enable", "true"); // 启用TLS加密
        return sender;
    }
}
